﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp1.Models;
using WpfApp1.Service;
using WpfApp1.Services;
using WpfApp1.ucontrol;
using WpfApp1.ViewModel;
using WpfApp1.ViewModels;
using static System.Runtime.CompilerServices.RuntimeHelpers;


namespace WpfApp1.Views
{
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindow
    {
      
        public LoginWindow()
        {
            InitializeComponent();
            this.DataContext = App.Current.Services.GetService(typeof(LoginViewModel));
        }
     
        private async void Button_Click(object sender, RoutedEventArgs e)
        {

            var httpRestClient = new HttpRestClient();
            LoginUserService loginUserService = new LoginUserService(httpRestClient);
            var accountStr = account.Text;
            var pwdStr = pwd.Password;
           
            var regResult = await loginUserService.Login(new LoginDto {  UserName=accountStr,Password=pwdStr });
            if (regResult.Code == 200)
            {
                var MainWindow = new MainAppWindow();
                MainWindow.Show();
                Close();
                var userInfo = regResult.Data;
                CurrentUserInfo.userId = userInfo.userId;
                CurrentUserInfo.UserName = userInfo.UserName;
            }
            else
            {
                Growl.Error(regResult.Msg);
               
            }
          
           var userid= CurrentUserInfo.userId;


        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Dialog.Show(new RegisterView());

        }
    }
}
